package top.haijunit.work.controller.system;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import top.haijunit.work.core.doamin.Result;
import top.haijunit.work.modules.access.domain.AssignRole;
import top.haijunit.work.modules.access.service.SubjectPermissionService;

/**
 * 访问授权
 *
 * @author zhanghaijun
 * @since 2024-08-30
 */
@Slf4j
@RestController
@RequestMapping("/access/assign")
@Tag(name = "访问授权")
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class AccessAssignController {

    private final SubjectPermissionService subjectPermissionService;

    @ApiOperationSupport(order = 30)
    @Operation(summary = "分配权限")
    @PostMapping("/assign/save")
    public Result<Void> assignSubjectToResource(@RequestBody @Valid AssignRole assignRole) {
        subjectPermissionService.assignRoleToSubject(assignRole);
        return Result.success();
    }
}
